package com.szpx.mapper;

import com.szpx.entity.TBUser;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author June
 * @version 1.0.0
 * @title tb_UserMapper
 * @create 2024/4/2 14:24
 * @description
 **/
@Mapper
public interface TBUserMapper {

    /**
     * 添加用户
     */
    @Insert("INSERT INTO tb_user(username,password,phone,regtime) values (#{username},#{password},#{phone},#{regtime})")
    int addUser(TBUser tbUser);

    /**
     * 根据手机号查询用户
     */
    @Select("SELECT uid,username,password,phone,email,regtime,balance FROM tb_user WHERE phone = #{phone}")
    TBUser selectByPhone(TBUser tbUser);

    /**
     * 充值
     *
     * @param
     * @return
     */

    @Update("UPDATE tb_user SET balance = #{balance} WHERE uid = #{uid}")
    int updateUserBalance(@Param("uid") Integer uid, @Param("balance") double balance);
    /**
     * 根据ID查询用户
     * @param uid
     * @return
     */
    @Select("SELECT uid,username,password,phone,email,regtime,balance FROM tb_user WHERE uid=#{uid}")

    TBUser selectByUid(Integer uid);

    /**
     * 查询所有用户信息
     * @return
     */
    @Select("SELECT uid,username,password,phone,email,regtime,balance FROM tb_user ")
    List<TBUser> findAll();

    /**
     * 用户账户管理修改用户email
     * @param tbUser
     */
    @Update(" UPDATE tb_user SET email = #{email} WHERE uid = #{uid}")
    void updateUserEmail(TBUser tbUser);

    /**
     * 修改用户名
     * @param tbUser
     */
    @Update(" UPDATE tb_user SET username = #{username} WHERE uid = #{uid}")
    void updateUserName(TBUser tbUser);

    /**
     * 修改手机号
     * @param tbUser
     */
    @Update(" UPDATE tb_user SET phone = #{phone} WHERE uid = #{uid}")
    void updateUserPhone(TBUser tbUser);
}
